/**
 * Copyright 2007 Luke Pillow
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package com.orsomethinglikethat.flex.filemaker.command
{
	import flash.net.URLRequest;
	import flash.events.FullScreenEvent;
	import flash.net.URLLoader;
	import flash.events.Event;
	import com.orsomethinglikethat.flex.filemaker.request.LayoutParameter;
	import com.orsomethinglikethat.flex.filemaker.request.Parameter;
	import com.orsomethinglikethat.flex.filemaker.request.FileMakerRequest;
	import com.orsomethinglikethat.flex.filemaker.FileMaker;
	import com.orsomethinglikethat.flex.filemaker.request.FileMakerResultEvent;
	import com.orsomethinglikethat.flex.filemaker.FileMakerResultHandler;
	
	public class Command
	{
		public var name:String;
		public var parameters:Array = new Array();
		
		public var layout:String;
		private var fileMaker:FileMaker;
		
		public function Command( fileMaker:FileMaker, name:String, layoutName:String )
		{
			super();
			this.name = name;
			this.layout = layoutName;
			this.fileMaker = fileMaker;
		}
		
		public function execute( resultHandler:Function, errorHandler:Function=null ):void
		{
			var fmResultHandler:FileMakerResultHandler = new FileMakerResultHandler();
			fmResultHandler.addEventListener( FileMakerResultEvent.COMPLETE, resultHandler );
			
			new FileMakerRequest( this.fileMaker, this ).execute( fmResultHandler.parse, errorHandler );
		}
		
		protected function addParameter( parameter:Parameter ):void
		{
			this.parameters.push( parameter );
		}
	}
}